/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cube.charts.cubedesign;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;

/**
 *
 * @author admin
 */
public class Colour implements Designable{
    
    private Graphics g;
    private double p[][];
    private double c[] = new double[9];
    private int x=1;
    private int y=2;
    private int z=3;
    private int w = 200;
    
    
    public void paint(){
            
        // Perspektive: *1+z/1000
        for (int i=1;i<9;i++) {
            c[i] = 1+p[i][z]/1000;
        }

        // Kreuzprodukt der eine Fläche aufspannenden Vektoren bilden
        // Wenn Betrag der z-Koordinate positiv: Fläche anzeigen

        if((p[1][x]*c[1]-p[2][x]*c[2])*(p[3][y]*c[3]-p[2][y]*c[2])
          -(p[1][y]*c[1]-p[2][y]*c[2])*(p[3][x]*c[3]-p[2][x]*c[2]) > 0) {
            // |2->1 x 2->3| > 0

            int xCoords1234[] = {(int)(p[1][x]*c[1])+w,(int)(p[2][x]*c[2])+w,
                                 (int)(p[3][x]*c[3])+w,(int)(p[4][x]*c[4])+w};
            int yCoords1234[] = {(int)(p[1][y]*c[1])+w,(int)(p[2][y]*c[2])+w,
                                 (int)(p[3][y]*c[3])+w,(int)(p[4][y]*c[4])+w};

            g.setColor(new Color(255,0,0));
            g.fillPolygon(new Polygon(xCoords1234,yCoords1234,4));
        }
        else if((p[7][x]*c[7]-p[6][x]*c[6])*(p[5][y]*c[5]-p[6][y]*c[6])
               -(p[7][y]*c[7]-p[6][y]*c[6])*(p[5][x]*c[5]-p[6][x]*c[6]) > 0) {
            // |6->7 x 6->5| > 0

            int xCoords5678[] = {(int)(p[5][x]*c[5])+w,(int)(p[6][x]*c[6])+w,
                                 (int)(p[7][x]*c[7])+w,(int)(p[8][x]*c[8])+w};
            int yCoords5678[] = {(int)(p[5][y]*c[5])+w,(int)(p[6][y]*c[6])+w,
                                 (int)(p[7][y]*c[7])+w,(int)(p[8][y]*c[8])+w};

            g.setColor(new Color(255,0,0));
            g.fillPolygon(new Polygon(xCoords5678,yCoords5678,4));
        }

        if((p[6][x]*c[6]-p[2][x]*c[2])*(p[1][y]*c[1]-p[2][y]*c[2])
          -(p[6][y]*c[6]-p[2][y]*c[2])*(p[1][x]*c[1]-p[2][x]*c[2]) > 0) {
            // |2->6 x 2->1| > 0

            int xCoords1265[] = {(int)(p[1][x]*c[1])+w,(int)(p[2][x]*c[2])+w,
                                 (int)(p[6][x]*c[6])+w,(int)(p[5][x]*c[5])+w};
            int yCoords1265[] = {(int)(p[1][y]*c[1])+w,(int)(p[2][y]*c[2])+w,
                                 (int)(p[6][y]*c[6])+w,(int)(p[5][y]*c[5])+w};

            g.setColor(new Color(0,255,0));
            g.fillPolygon(new Polygon(xCoords1265,yCoords1265,4));
        }
        else if((p[4][x]*c[4]-p[3][x]*c[3])*(p[7][y]*c[7]-p[3][y]*c[3])
               -(p[4][y]*c[4]-p[3][y]*c[3])*(p[7][x]*c[7]-p[3][x]*c[3]) > 0) {
            // |3->4 x 3->7| > 0

            int xCoords4378[] = {(int)(p[4][x]*c[4])+w,(int)(p[3][x]*c[3])+w,
                                 (int)(p[7][x]*c[7])+w,(int)(p[8][x]*c[8])+w};
            int yCoords4378[] = {(int)(p[4][y]*c[4])+w,(int)(p[3][y]*c[3])+w,
                                 (int)(p[7][y]*c[7])+w,(int)(p[8][y]*c[8])+w};

            g.setColor(new Color(0,255,0));
            g.fillPolygon(new Polygon(xCoords4378,yCoords4378,4));
        }

        if((p[3][x]*c[3]-p[2][x]*c[2])*(p[6][y]*c[6]-p[2][y]*c[2])-(p[3][y]*c[3]
           -p[2][y]*c[2])*(p[6][x]*c[6]-p[2][x]*c[2]) > 0) {
            // |2->3 x 2->6| > 0

            int xCoords2376[] = {(int)(p[2][x]*c[2])+w,(int)(p[3][x]*c[3])+w,
                                 (int)(p[7][x]*c[7])+w,(int)(p[6][x]*c[6])+w};
            int yCoords2376[] = {(int)(p[2][y]*c[2])+w,(int)(p[3][y]*c[3])+w,
                                 (int)(p[7][y]*c[7])+w,(int)(p[6][y]*c[6])+w};

            g.setColor(new Color(0,0,255));
            g.fillPolygon(new Polygon(xCoords2376,yCoords2376,4));
        }
        else if((p[5][x]*c[5]-p[1][x]*c[1])*(p[4][y]*c[4]-p[1][y]*c[1])
               -(p[5][y]*c[5]-p[1][y]*c[1])*(p[4][x]*c[4]-p[1][x]*c[1]) > 0) {
            // |1->5 x 1->4| > 0

            int xCoords1485[] = {(int)(p[1][x]*c[1])+w,(int)(p[4][x]*c[4])+w,
                                 (int)(p[8][x]*c[8])+w,(int)(p[5][x]*c[5])+w};
            int yCoords1485[] = {(int)(p[1][y]*c[1])+w,(int)(p[4][y]*c[4])+w,
                                 (int)(p[8][y]*c[8])+w,(int)(p[5][y]*c[5])+w};

            g.setColor(new Color(0,0,255));
            g.fillPolygon(new Polygon(xCoords1485,yCoords1485,4));
        }
    }

    public void setG(Graphics g) {
        this.g = g;
    }

    public void setP(double[][] p) {
        this.p = p;
    }
    
}



